#ifndef PROJECTEVENTBUS
#define PROJECTEVENTBUS

#include <map>
#include <set>
#include <iostream>

#include "../../SDK/include/Events.h"
#include "iprojectplugin.h"

class ProjectEventBus
{
    public:
        static ProjectEventBus* self();
        ~ProjectEventBus();

        void AttachListener( Events::EventType type, IProjectPlugin* plugin ) { managerlisteners[type].insert( plugin ); }
        void DettachListener( Events::EventType type, IProjectPlugin* plugin ) { managerlisteners[type].erase( plugin ); }
        void PublishEvent( Events::Event* event )
        {
            std::set<IProjectPlugin*> receivers = managerlisteners[ event->GetType() ];
            std::set<IProjectPlugin*>::iterator it = receivers.begin();
            std::set<IProjectPlugin*>::iterator end = receivers.end();
            while ( it != end ) {
                std::cerr << "handle it .....\n";
                (*it)->HandleEvent( event );
                ++it;
            }
        }
    private:
        static ProjectEventBus* m_self;
        ProjectEventBus();

        std::map<Events::EventType, std::set<IProjectPlugin*> > managerlisteners;
};

#endif // PROJECTEVENTBUS
